﻿using System;
using Ewk.Math.ComputationTypes;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Ewk.Math.Algebra.UnitTests
{
    [TestClass]
    public class VectorFunctionUnitTests : VectorUnitTestsBase<Function<double, double>>
    {
        [TestMethod]
        public void VectorFunction_Norm_computes_the_euclidian_norm_of_the_vector()
        {
            var vector1 = CreateVector
                (
                    new Function<double, double>(
                        input => (input - 3) * 3),
                    new Function<double, double>(
                        input => (input + 2) * 5)
                );
            var norm = vector1.Norm;

            // norm = 
            // Sqrt(((x-3)*3)^2 + ((x+2)*5)^2) = 
            // Sqrt((3x-9)^2 + (5x+10)^2) = 
            // Sqrt(9x^2 - 54x + 81 + 25x^2 + 100x + 100) = 
            // Sqrt((9+25)x^2 + (100-54)x + 100+81 = 
            // Sqrt(34x^2 + 46x + 181)
            Func<double, double> f = x => System.Math.Sqrt(34*x*x + 46*x + 181);

            Assert.AreEqual(f(2), norm.Value.Func(2).Value);
            Assert.AreEqual(f(5), norm.Value.Func(5).Value);
        }
    }
}
